<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 2017/6/25
 * Time: 21:16
 */

session_start();
$method = $_SERVER['REQUEST_METHOD'];

if ( isset( $_SERVER["HTTP_X_REQUESTED_WITH"] )
     and
     strtolower( $_SERVER["HTTP_X_REQUESTED_WITH"] ) == "xmlhttprequest"
) {
	if ( ! isset( $_REQUEST['token'] ) || $_REQUEST['token'] !== $_SESSION['token'] ) {
		echo json_encode( [
			'status' => false,
			'$_SESSION'  => $_SESSION['token'],
			'$_REQUEST'  => $_REQUEST['token']
		] );
		die();
	}
	if ( $method === "POST" ) {
		$name = $_POST['name'];
		echo json_encode( [
			'status' => true,
			'type'   => $method,
			'name'   => $name
		] );

	} elseif ( $method === "GET" ) {
		$name = $_GET['name'];
		echo json_encode( [
			'status' => true,
			'type'   => $method,
			'name'   => $name
		] );
	} else {
		echo "fuck";
	}
}else{
	echo "GET OUT !! ";
}
die();

